/**
 * 
 */
var Release = function() {
	return {
		exeData : function(url) {
			var timeOut = 0;
			var wait = setInterval(function() {
				var code = $(".code").val();
				$.ajax({
					type : "post",
					url : url,
					data : {
						"scode" : code
					},
					dataType : "json",
					async : true,
					success : function(data) {
						if (data.returnCode == 0) {
							clearInterval(wait);
							//执行资源回调
							Release.bindResult(data.data);
						}else if(data.returnCode == 200){
							$(".time_out").css("display","block");
							$(".time_out>p").html("设备已扫描,请授权");
						}else if(data.returnCode == 404){
							$(".time_out").css("display","block");
							$(".time_out>p").html("二维码过期");
							clearInterval(wait);
						}else if(data.returnCode ==201 ){
							$(".time_out").css("display","block");
							$(".time_out>p").html("用户已取消授权");
							clearInterval(wait);
						}
					},
					error : function() {
						clearInterval(wait);
						$(".time_out").css("display","block");
						return;
					}
				});
				if(timeOut == 60){
					clearInterval(wait);
					$(".time_out").css("display","block");
				}
				timeOut += 1;
			}, 1000);
		},
		bindResult : function(url) {
			var timeOut = 0;
			var wait = setInterval(function() {
				$.ajax({
					type : "post",
					url : url,
					dataType : "json",
					async : true,
					success : function(data) {
						if (data.returnCode == 0) {
							clearInterval(wait);
							$(".time_out").css("display","block");
							$(".time_out>p").html("绑定成功");
						}else if(data.returnCode == -1){
							clearInterval(wait);
							$(".time_out").css("display","block");
							$(".time_out>p").html(data.returnMessage);
						}else {
							clearInterval(wait);
						}
					},
					error : function() {
						clearInterval(wait);
						return;
					}
				});
				if(timeOut == 60){
					clearInterval(wait);
					$(".time_out").css("display","block");
				}
				timeOut += 1;
			}, 1000);
		},
		refresh : function(){
			location.href= $(".refresh-url").val();
		}
	};
}();